
class TestContext {
    loading = $state(false);
    data = $state(null);
    error = $state(false);
    errorMsg = $state(null);

    async load() {
        this.loading = true;
        let response = await fetch('/api/app/main/user/list', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json',
                'x-request-entry': false,
                'x-request-host': 'dlqykj',
                'x-request-token': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3Mzc2MTA4MTQzODYsImp0aSI6IllUY3paVGN4WWpjdFlUbGpNQzAwTmpVMExXRmtaall0TlRjMlptTmlZamxsTXpKbSIsIlhYIyQlKCkoIyohKCkhS0w8PjxNUUxNTlFOUUpRSyBzZGZranNkcm93MzIyMzQ1NDVmZGY-P048OntMV1BXIjoie1widXNlcklkXCI6XCIxNzk1Njc3MjQ5MzU2NDM1NDU2XCIsXCJvcmdJZFwiOlwiMTcwMDAwMTAwMDEwMDAwMDAwXCIsXCJob3N0XCI6XCJkbHF5a2pcIixcImxvZ0lkXCI6XCJUbzNtcWFZOGUzNXpRek5sZUhkRlUySjRWcDU4U1ZURFwiLFwiZW50cnlcIjpcIjE3MDAwMDAwMDAwMDAwMDEwMFwifSJ9.-D2UzaCTJpW0JZFCLgTAaD1h9EwDgOWpnBa9O3ZKbvw'
            },
            body: JSON.stringify({
                "client": true,
                "deptId": "1795677249356435457"
            })
        });
        if (response.ok) {
            const { code, msg, data } = await response.json();
            this.data = data;
            if (code == 0) {
                this.error = false;
                this.loading = false;
            } else {
                this.error = this;
                this.errorMsg = msg;
            }
        } else {
            this.data = null;
            this.error = true;
            this.errorMsg = response.statusText;
            this.loading = false;
        }
    }
}

export const context = new TestContext();